import 'package:flutter/material.dart';
import 'package:shared_preferences.dart';

class ThemeService {
  static const String _themePrefsKey = 'theme_mode';
  static const String _primaryColorPrefsKey = 'primary_color';
  
  static final ThemeService instance = ThemeService._init();
  final _prefs = SharedPreferences.getInstance();
  
  ThemeService._init();

  /// 获取主题模式
  Future<ThemeMode> getThemeMode() async {
    final prefs = await _prefs;
    final value = prefs.getString(_themePrefsKey);
    return ThemeMode.values.firstWhere(
      (mode) => mode.name == value,
      orElse: () => ThemeMode.system,
    );
  }

  /// 保存主题模式
  Future<void> setThemeMode(ThemeMode mode) async {
    final prefs = await _prefs;
    await prefs.setString(_themePrefsKey, mode.name);
  }

  /// 获取主题色
  Future<Color> getPrimaryColor() async {
    final prefs = await _prefs;
    final value = prefs.getInt(_primaryColorPrefsKey);
    return Color(value ?? Colors.blue.value);
  }

  /// 保存主题色
  Future<void> setPrimaryColor(Color color) async {
    final prefs = await _prefs;
    await prefs.setInt(_primaryColorPrefsKey, color.value);
  }

  /// 获取预定义的主题色列表
  static List<Color> get predefinedColors => [
    Colors.blue,
    Colors.green,
    Colors.purple,
    Colors.orange,
    Colors.red,
    Colors.teal,
    Colors.pink,
    Colors.indigo,
  ];
} 